﻿using System;
namespace Producers.Rr.Xtee.Riik.Ee.Producer.Rr {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="RR67Response", Namespace="http://producers.rr.xtee.riik.ee/producer/rr", Target=typeof(RR67Response))]
    public class RR67ResponseSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IRR67Response clazz;
        
        public RR67ResponseSerializer(IRR67Response clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("ttKoodid");
            if (clazz.TtKoodid!=null) {
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute(">>>RR67Response>ttKoodid>ttKoodid", "http://producers.rr.xtee.riik.ee/producer/rr", clazz.TtKoodid.Count);
                for (int x = 0; ((clazz.TtKoodid != null) 
                            && (x < clazz.TtKoodid.Count)); x = (x + 1)) {
                    if (clazz.TtKoodid[x]!=null) {
                        Writer.WriteStartElement("ttKoodid");
                        global::Xtee.Core.SerializationMetadata metaTtKoodid = this.GetMetaData(clazz.TtKoodid[x]);
                        Writer.WriteTypeAttribute(metaTtKoodid.TypeQualifiedName.Namespace, metaTtKoodid.TypeQualifiedName.Name);
                        metaTtKoodid.NewSerializer(clazz.TtKoodid[x]).WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : TtKoodid");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="ttKoodid") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RR67Response>ttKoodid");
                }
                clazz.TtKoodid = new System.Collections.Generic.List<RR67Response.ITtKoodidType>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("ttKoodid");
                    for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                && (Reader.LocalName == "ttKoodid")); ) {
                        if (Reader.IsElementNil()) {
                            throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>RR67Response>ttKoodid>ttKoodid");
                        }
                        global::Xtee.Core.SerializationMetadata metaTtKoodid = this.GetMetaData<RR67Response.ITtKoodidType>(Reader, ">>>RR67Response>ttKoodid>ttKoodid", "http://producers.rr.xtee.riik.ee/producer/rr");
                        RR67Response.ITtKoodidType item = metaTtKoodid.NewEntity<RR67Response.ITtKoodidType>();
                        clazz.TtKoodid.Add(item);
                        if ((Reader.IsEmptyElement == false)) {
                            Reader.ReadStartElement("ttKoodid");
                            metaTtKoodid.NewSerializer(item).ReadXml(Reader);
                            Reader.ReadEndElement();
                        }
                        else {
                            Reader.Skip();
                        }
                    }
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RR67Response>ttKoodid", Reader.LocalName);
            }
        }
        
        [global::Xtee.Core.Attributes.XmlTypeAttribute(Name=">>>RR67Response>ttKoodid>ttKoodid", Namespace="http://producers.rr.xtee.riik.ee/producer/rr", Target=typeof(RR67Response.TtKoodidType))]
        public class TtKoodidTypeSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
            
            protected RR67Response.ITtKoodidType clazz;
            
            public TtKoodidTypeSerializer(RR67Response.ITtKoodidType clazz) {
                this.clazz = clazz;
            }
            
            public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
                base.WriteXml(Writer);
                Writer.WriteStartElement("ttKoodid.cIsikukood");
                if (clazz.TtKoodidcIsikukood!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.TtKoodidcIsikukood))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : TtKoodidcIsikukood");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("ttKoodid.cUusKood");
                if (clazz.TtKoodidcUusKood!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.TtKoodidcUusKood))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : TtKoodidcUusKood");
                }
                Writer.WriteEndElement();
            }
            
            public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
                base.ReadXml(Reader);
                if (Reader.LocalName=="ttKoodid.cIsikukood") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR67Response>ttKoodid>ttKoodid>ttKoodid.cIsikukood");
                    }
                    clazz.TtKoodidcIsikukood = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("ttKoodid.cIsikukood")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR67Response>ttKoodid>ttKoodid>ttKoodid.cIsikukood", Reader.LocalName);
                }
                if (Reader.LocalName=="ttKoodid.cUusKood") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR67Response>ttKoodid>ttKoodid>ttKoodid.cUusKood");
                    }
                    clazz.TtKoodidcUusKood = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("ttKoodid.cUusKood")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR67Response>ttKoodid>ttKoodid>ttKoodid.cUusKood", Reader.LocalName);
                }
            }
        }
    }
}
